﻿@model IEnumerable<MvcAtletIS.Models.Statistics>
@{ 
    ViewBag.Title = "Štatistika"; 
}

<h2>Štatistika - Prehľad pre pretekára</h2>

<p>
    Vyberte rok a pretekára, pre ktorého chcete zobraziť prehľad štatistiky.
</p>

@using (Html.BeginForm())
{   
    
    <div class="filter-frame">
        
        <div class="filter-item">
            <div class="editor-label">
                Rok
            </div>
            <div class="editor-field">
                @Html.DropDownList("selectedYear", null, "Vyberte rok", new { onchange = "this.form.submit();" })
            </div>
        </div>

        <div class="filter-item">
            <div class="editor-label">
                Klub
            </div>
            <div class="editor-field">
                @Html.DropDownList("selectedClubId", "Vyberte klub")
            </div>
        </div>

        <div class="filter-item">
            <div class="editor-label">
                Pretekár
            </div>
            <div class="editor-field">
                @Html.DropDownList("selectedCompetitorId", null, "Vyberte pretekára", new { onchange = "this.form.submit();" })
            </div>
        </div>

    </div>
}

<p></p>

@if (ViewBag.selectedCompetitor != null)
{
    <table>
        <tr>
            <td>
                @if (ViewBag.selectedCompetitor.bImage)
                {                
                    <img src="@Url.Content("~/Content/competitors/" + ViewBag.selectedCompetitor.ID + ".jpg")" alt="AtletIS" class="contact-image" />
                }
                else
                {
                    <img src="@Url.Content("~/Content/competitors/empty.jpg")" alt="AtletIS" class="contact-image" />
                }
            </td>
            <td>
                <div class="profile-name">
                    @ViewBag.selectedCompetitor.FullName
                </div>

                @ViewBag.selectedCompetitor.Clubs.Name <br />
                @ViewBag.selectedCompetitor.Birthdate.ToShortDateString() <br />

                <p>
                    <img src="@Url.Content("~/Content/flags/24px/" + ViewBag.selectedCompetitor.CountryId + ".png")" alt="AtletIS" />
                </p>
            </td>
        </tr>
    </table>
}

@if (Model.Count() > 0)
{
    <table width="100%">
        <tr>
            <th width="300px">
                Pretekár
            </th>
            <th width="200px">
                Disciplína
            </th>
            <th width="200px">
                Preteky
            </th>
            <th width="100px">
                Dátum
            </th>
            <th width="100px">
                Výkon
            </th>
            <th width="50px">
                Halový
            </th>
            <th width="50px">
                Elektr.
            </th>
            <th>
                Poznámka
            </th>
        </tr>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Competitors.FullName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Disciplines.Name)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.StatisticsCompetitions.City)
                </td>
                <td align="right">
                    @Html.DisplayFor(modelItem => item.StatisticsCompetitions.Date)
                </td>
                <td align="center">
                    @Html.DisplayFor(modelItem => item.sResult)
                </td>
                <td align="center">
                    @Html.DisplayFor(modelItem => item.Indoor)
                </td>
                <td align="center">
                    @Html.DisplayFor(modelItem => item.Electronic)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Note)
                </td>
            </tr>
        }
    </table>
    
    <p>
        @Html.Label(" Počet záznamov: " + Model.Count().ToString())
    </p>
}

<script type="text/javascript">
    $(document).ready(function () {
        $("#selectedClubId").change(function () {
            var idModel = $(this).val();
            $.getJSON("/Statistics/LoadCompetitorsForClub", { id: idModel },
            function (competitorsData) {
                var select = $("#selectedCompetitorId");
                select.empty();
                select.append($('<option/>',
                {
                    value: 0,
                    text: "Vyberte pretekára"
                }));
                $.each(competitorsData, function (index, itemData) {
                    select.append($('<option/>',
                    {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
            });
        });
    });
</script>
